package com.funo.business.service.impl;

import java.util.UUID;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.funo.business.dao.CompanyDao;
import com.funo.business.entities.Company;
import com.funo.business.service.CompanyService;
import com.funo.common.pojo.PageResult;
import com.funo.common.pojo.QueryCondition;
import com.funo.common.utils.Constant;
import com.funo.core.base.BaseService;

@Service("companyService")
public class CompanyServiceImpl extends BaseService implements CompanyService{
	
	@Autowired
	@Qualifier("companyDao")
	private CompanyDao companyDao;

	@Override
	public void delCompany(String companyId) {
		// TODO Auto-generated method stub
		//假删除设置
		Company company = companyDao.get(companyId);
		company.setIsValid(0);
		companyDao.save(company);
	}

	@Override
	public Company getCompany(String companyId) {
		// TODO Auto-generated method stub
		return companyDao.get(companyId);
	}

	@Override
	public Company getCompanyByUserId(String userId) {
		// TODO Auto-generated method stub
		return companyDao.getCompany(userId);
	}

	@Override
	public Integer saveCompany(Company company) {
		// TODO Auto-generated method stub
		company.setCompanyId(UUID.randomUUID().toString());
		//int i = 1/0;
		companyDao.save(company);
		return Constant.STATUS_SUSSESS;
	}

	@Override
	public Integer updateCompany(Company company) {
		// TODO Auto-generated method stub
		Company company2 = companyDao.get(company.getCompanyId());
		BeanUtils.copyProperties(company, company2,new String[]{"companyId"});
		companyDao.update(company2);
		return Constant.STATUS_SUSSESS;
	}

	@Override
	public PageResult<Company> listPage(QueryCondition condition,
			Company company) {
		// TODO Auto-generated method stub
		PageResult<Company> page = new PageResult<Company>();
		page.setList(companyDao.pageList(condition, company));
		page.setTotal(companyDao.count(condition, company));
		return page;
	}
	
}
